using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Collections;
using System.Data.Odbc;
using System.Data.OleDb;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Data.SqlTypes;

namespace RUPS
{
    public partial class AdaugareComponentaComanda : Form
    {
        string numeFisTexturiLemn;
        string numeFisPrivacyGlass;
        ArrayList texturiLemnoase;
        ArrayList tipuriPrivacyGlass;
        public static string caleFisier;

        public static string IDComanda;
        public static string IDClient;
        public static DateTime dataComanda;
        public static DateTime dataLivrare;
        public static string detaliiClient;

        public AdaugareComponentaComanda(string IDComanda1,string IDClient1,string detaliiClient1,DateTime dataComanda1,DateTime dataLivrare1)
        {
            
            InitializeComponent();
            CenterToScreen();
            IDComanda = IDComanda1;
            IDClient = IDClient1;
            dataComanda = dataComanda1;
            dataLivrare = dataLivrare1;
            detaliiClient = detaliiClient1;

            this.dataComandaDateTimePicker.Value = dataComanda;
            this.dataLivrareDateTimePicker.Value = dataLivrare;
            this.codClientComboBox.SelectedItem =IDClient;
            this.detaliiClientTextBox.Text = detaliiClient;

            numeFisTexturiLemn =
                    System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
            numeFisTexturiLemn += ("\\texturi lemnoase\\texturi lemnoase.txt");

            texturiLemnoase = new ArrayList();
            string linie;

            using (StreamReader stream = File.OpenText(numeFisTexturiLemn))
            {
                linie = stream.ReadLine();
                texturiLemnoase.Add(linie);
                while (linie != null)
                {
                    linie = stream.ReadLine();
                    if (linie != null)
                        texturiLemnoase.Add(linie);
                }
            }

            //if (texturiLemnoase.Count > 0)
            //    foreach (string s in texturiLemnoase)
            //        this.comboBoxTexturiLemnoase.Items.Add(s);
            //this.comboBoxTexturiLemnoase.Enabled = false;
            //this.button1.Enabled = false;
            numeFisPrivacyGlass = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
            numeFisPrivacyGlass+=("\\privacy glass\\privacy glass.txt");
            tipuriPrivacyGlass = new ArrayList();

            using (StreamReader stream = File.OpenText(numeFisPrivacyGlass))
            {
                linie = stream.ReadLine();
                this.tipuriPrivacyGlass.Add(linie);
                while (linie != null)
                {
                    linie = stream.ReadLine();
                    if (linie != null)
                        this.tipuriPrivacyGlass.Add(linie);
                }
                
            }
            if (this.tipuriPrivacyGlass.Count > 0)
                foreach (string s in this.tipuriPrivacyGlass)
                    this.comboBoxPrivacyGlass.Items.Add(s);
        }



        private void comboBoxTipCanat_SelectedIndexChanged(object sender, EventArgs e)
        {
            int nrTipCanat;
            string caleFisierImagine = 
                System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
            nrTipCanat = this.comboBoxTipCanat.SelectedIndex;
            caleFisierImagine += ("\\cod comanda\\"+nrTipCanat.ToString()+".bmp");
            this.pictureBoxTipCanat.ImageLocation = caleFisierImagine;
            

            

        }

        private void button1_Click(object sender, EventArgs e)
        {
           
        }

        private void comboBox4_SelectedIndexChanged(object sender, EventArgs e)
        {
        }

        private void comboBoxTexturiLemnoase_SelectedIndexChanged(object sender, EventArgs e)
        {
            int i = 0;
            string numeFis=null;
            foreach (string s in texturiLemnoase)
            {
                //if (i == this.comboBoxTexturiLemnoase.SelectedIndex)
                //{
                //    numeFis = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
                //    numeFis += "\\texturi lemnoase\\"+s+".bmp";
                //}
                i++;
            }
            if (numeFis != null)
            {
                //this.pictureBoxTexturaLemnoasa.BackgroundImage = new Bitmap(numeFis);
                //this.pictureBoxTexturaLemnoasa.BackgroundImageLayout = ImageLayout.Stretch;
            }

        }

        private void CreareComanda_Load(object sender, EventArgs e)
        {
            
            // TODO: This line of code loads data into the 'masivDBDataSet.clienti' table. You can move, or remove it, as needed.
            //this.clientiTableAdapter.Fill(this.masivDBDataSet.clienti);
            
            //populare combobox cu clienti
            
            //codClientComboBox.DataSource = null;
            //DataSet ds = new DataSet();
            //SqlDataAdapter da = new SqlDataAdapter("select * from clienti", this.clientiTableAdapter.Connection);
            //da.Fill(ds, "clienti");
            //foreach (DataRow r in ds.Tables["clienti"].Rows)
            //{ 
            //    string itemComboBox = "";
            //    itemComboBox += r["ID"] + ", ";
            //    itemComboBox += r["nume"] + ", ";
            //    itemComboBox += r["prenume"];
            //    codClientComboBox.Items.Add(itemComboBox);
            //}

            ////popularea culoriDataGridView cu membri 
            //caleFisier = AppDomain.CurrentDomain.BaseDirectory;
            //caleFisier += "texturi lemnoase\\texturi lemnoase.txt";
            //using (StreamReader stream = File.OpenText(caleFisier))
            //{
            //    int nrRand = 0;
            //    string calePoza;
            //    string linie = stream.ReadLine();
            //    string[] sirCaracteristiciCuloare;
            //    string cod, denumire, calePozaCuloare;
            //    while (linie != null)
            //    {
            //        cod = "";
            //        calePozaCuloare = AppDomain.CurrentDomain.BaseDirectory;
            //        calePozaCuloare += "texturi lemnoase\\";
            //        denumire = "";
            //        sirCaracteristiciCuloare = linie.Split(' ');
            //        cod = sirCaracteristiciCuloare[0];
            //        calePozaCuloare += cod + ".jpg";
            //        if (sirCaracteristiciCuloare.Length > 2)
            //        {
            //            for (int i = 1; i < sirCaracteristiciCuloare.Length; i++)
            //            {
            //                denumire += sirCaracteristiciCuloare[i] + " ";
            //            }
            //        }
            //        else
            //            denumire = sirCaracteristiciCuloare[1];
            //        this.culoriDataGridView.Rows.Add();
            //        this.culoriDataGridView.Rows[nrRand].Cells[0].Value = cod;
            //        this.culoriDataGridView.Rows[nrRand].Cells[1].Value = denumire;
            //        System.Drawing.Image imagine = new Bitmap(calePozaCuloare);
            //        this.culoriDataGridView.Rows[nrRand].Cells[2].Value = imagine;
            //        nrRand++;
            //        linie = stream.ReadLine();
            //    }
            //}
            //comboBoxTipPlasa.Enabled = false;


        }

        private void comboBoxPrivacyGlass_SelectedIndexChanged(object sender, EventArgs e)
        {
           
            string caleFisierImagine =
                System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
            string tipPrivacyGlass = this.comboBoxPrivacyGlass.SelectedItem.ToString();
            caleFisierImagine += ("\\privacy glass\\" + tipPrivacyGlass + ".bmp");
            //this.pictureBoxPrivacyGlass.ImageLocation = caleFisierImagine;
            this.pictureBoxPrivacyGlass.BackgroundImage = new Bitmap(caleFisierImagine);
            this.pictureBoxPrivacyGlass.BackgroundImageLayout = ImageLayout.Stretch;
            
           
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Visible = false;
            int x = this.Location.X,
                y = this.Location.Y;
            //AdaugareComponentaComanda f1 = new AdaugareComponentaComanda();
            //f1.Visible = true;
            //f1.Location=new Point(x,y);
        }

        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            this.Visible = false;
        }

        private void buttonOK_Click(object sender, EventArgs e)
        {
            this.Visible = false;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            CreareFacturaForm f1 = new CreareFacturaForm();
            f1.Visible = true;
            f1.Location = new Point(this.Location.X, this.Location.Y);
        }

        private void button4_Click(object sender, EventArgs e)
        {
            CreareChitantaForm f1 = new CreareChitantaForm();
            f1.Location = new Point(this.Location.X, this.Location.Y);
            f1.Visible = true;
        }

        private void button5_Click(object sender, EventArgs e)
        {

        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }

        private void label3_Click(object sender, EventArgs e)
        {

        }

        private void radioButtonDa_CheckedChanged(object sender, EventArgs e)
        {
            if(radioButtonDa.Checked==true)
            this.radioButtonNu.Checked = false;
        }

        private void radioButtonNu_CheckedChanged(object sender, EventArgs e)
        {
            if(radioButtonNu.Checked==true)
            this.radioButtonDa.Checked = false;
        }

        private void dateTimePicker1_DropDown(object sender, EventArgs e)
        {
            

        }

        private void dataComandaDateTimePicker_ValueChanged(object sender, EventArgs e)
        {
            DateTime dataComanda = dataComandaDateTimePicker.Value;
            dataLivrareDateTimePicker.Value = dataComanda.AddDays(7);
        }

        private void dataLivrareDateTimePicker_ValueChanged(object sender, EventArgs e)
        {
            
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string[] sirDateClient=codClientComboBox.SelectedItem.ToString().Split(',');
            int i = 0;
            foreach (string s in sirDateClient)
            {
                if (s.StartsWith(" "))
                    s.Remove(0, 1);
                sirDateClient[i] = s;
                i++;
            }
            DataSet ds=new DataSet();
            SqlDataAdapter da=new SqlDataAdapter("select * from clienti where ID="+sirDateClient[0].ToString(),clientiTableAdapter.Connection);
            da.Fill(ds,"clienti");
            this.detaliiClientTextBox.Text = "";
            if (ds.Tables["clienti"].Rows[0]["adresa1"].ToString() != null)
                this.detaliiClientTextBox.Text += "Adresa: " + ds.Tables["clienti"].Rows[0]["adresa1"].ToString()+"\r\n";
            else
                if (ds.Tables["clienti"].Rows[0]["adresa2"].ToString() != null)
                    this.detaliiClientTextBox.Text += "Adresa: " + ds.Tables["clienti"].Rows[0]["adresa2"].ToString()+"\r\n";
            if (ds.Tables["clienti"].Rows[0]["localitate"].ToString() != null)
                this.detaliiClientTextBox.Text += " Localitate: "+ds.Tables["clienti"].Rows[0]["localitate"].ToString()+"\r\n";
            if(ds.Tables["clienti"].Rows[0]["telefon"].ToString() != null)
                this.detaliiClientTextBox.Text+="Tel. :"+ds.Tables["clienti"].Rows[0]["telefon"].ToString()+"\r\n";
            if(ds.Tables["clienti"].Rows[0]["email"].ToString() != null)
                this.detaliiClientTextBox.Text+="Email: "+ds.Tables["clienti"].Rows[0]["email"].ToString()+"\r\n";
            if(ds.Tables["clienti"].Rows[0]["tip"].ToString()=="True")
                this.detaliiClientTextBox.Text+="Tip: persoana juridica";
            else
                this.detaliiClientTextBox.Text+="Tip: persoana fizica";



        }

        private void codClientComboBox_TextChanged(object sender, EventArgs e)
        {
            comboBox1_SelectedIndexChanged(sender, e);
        }

        private void codClientComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            comboBox1_SelectedIndexChanged(sender, e);
        }

        private void comboBoxTipCanat_SelectedIndexChanged_1(object sender, EventArgs e)
        {
            comboBoxTipCanat_SelectedIndexChanged(sender, e);
        }

        private void comboBoxPrivacyGlass_SelectedIndexChanged_1(object sender, EventArgs e)
        {
            comboBoxPrivacyGlass_SelectedIndexChanged(sender, e);
        }

        private void radioButtonDa_CheckedChanged_1(object sender, EventArgs e)
        {
            if (radioButtonDa.Checked == true)
            {
                comboBoxTipPlasa.Enabled = true;
                radioButtonNu.Checked = false;
            }
        }

        private void radioButtonNu_CheckedChanged_1(object sender, EventArgs e)
        {
            if (radioButtonNu.Checked == true)
            {
                radioButtonDa.Checked = false;
                comboBoxTipPlasa.Enabled = false;
            }
        }

        private void dataComandaDateTimePicker_ValueChanged_1(object sender, EventArgs e)
        {

        }

        private void label12_Click(object sender, EventArgs e)
        {

        }

        private void detaliiClientTextBox_TextChanged(object sender, EventArgs e)
        {

        }

        private void label13_Click(object sender, EventArgs e)
        {

        }

        private void label17_Click(object sender, EventArgs e)
        {

        }

        private void label18_Click(object sender, EventArgs e)
        {

        }

        private void dataLivrareDateTimePicker_ValueChanged_1(object sender, EventArgs e)
        {
            dataComandaDateTimePicker_ValueChanged(sender, e);
        }

       
        

       
    }
}